package control;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import bean.User;

@Controller
public class UserControl {

	@Resource
	Dao dao;
	
	@RequestMapping(value="/listerUsers",method=RequestMethod.GET)
	public @ResponseBody List <User> listerUsers() {
		System.out.println("listerUsers");

		return dao.getUsers();
	}
	
	@RequestMapping(value="/addUser",method=RequestMethod.POST)
	public @ResponseBody User addUser(String name, String password, String mail){
		System.out.println("addUser");
		return dao.addUser(name, password, mail);
	}
	
	@RequestMapping(value="/addUserObject",method=RequestMethod.POST)
	public @ResponseBody User addUserObject(User user){
		System.out.println("addUserObject");
		return dao.addUser(user.getName(), user.getPassword(), user.getEmail());
	}
	
	//j'ai un doute sur ce type de requette, get post ?
	@RequestMapping(value="/removeUserById",method=RequestMethod.GET)
	public @ResponseBody boolean removeUser(int idUser){
		System.out.println("removeUserById");
		return dao.removeUser(idUser);
	}
	
	@RequestMapping(value="/modifiyUser",method=RequestMethod.GET)
	public @ResponseBody boolean modifiyUser(int idxUser, String name, String password, String email){
		System.out.println("modifiyUser");
		return dao.modifiyUser(idxUser, name, password, email);
	}
	
	@RequestMapping(value="/connexionUser",method=RequestMethod.GET)
	public @ResponseBody boolean connexionUser(String log, String password){
		System.out.println("modifiyUser");
		return dao.connexionUser(log, password);
	}
	
	@RequestMapping(value="/getUser",method=RequestMethod.GET)
	public @ResponseBody User getUser( int idxUser){
		System.out.println("getUser");
		return dao.getUser(idxUser);
	}
		
}
